import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { setupSwagger } from './common/swagger';
import { getLocalIp } from './utils/ip.config';
import { ValidationPipe } from '@nestjs/common';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);

  app.setGlobalPrefix('api');
  // 应用全局验证管道
  app.useGlobalPipes(new ValidationPipe());

  setupSwagger(app);

  // 全局跨域 可配置白名单
  //   {
  //   origin: 'http://localhost:5173',
  //   credentials: true,
  // }
  app.enableCors();

  const appPort = process.env.APP_PORT;
  await app.listen(appPort || 8085, '0.0.0.0');

  console.log(`🚀 Local http://localhost:${appPort}`);
  console.log(`🚀 Network http://${getLocalIp()}:${appPort}`);
}
bootstrap();
